package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.SignalMachineFaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/7/22.
 */
@Controller
@RequestMapping("/rds_signalMachineFault")
public class SignalMachineFaultController {
    @Resource
    private SignalMachineFaultService signalMachineFaultService;

    @RequestMapping(value = "/getMachineReportFault4DT")
    @ResponseBody
    public DTResponseDto getMachineReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signalMachineFaultService.getMachineReportFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getSignalMachineInfo2Fault")
    @ResponseBody
    public JsonMsgDto getSignalMachineInfo2Fault(Integer signalMachineId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineFaultService.getSignalMachineInfo2Fault(signalMachineId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignalMachineFaultInfo2Fault")
    @ResponseBody
    public JsonMsgDto getSignalMachineFaultInfo2Fault(Integer signalMachineId, Integer machineFaultId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineFaultService.getSignalMachineFaultInfo2Fault(signalMachineId, machineFaultId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateSignalMachineFault")
    @ResponseBody
    public JsonMsgDto updateSignalMachineFault(Integer machineFaultId, Integer machineLevel, Integer machineType, String machinePhoto, String machineReason, Double machineMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineFaultService.updateSignalMachineFault(machineFaultId, machineLevel, machineType, machinePhoto, machineReason, machineMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getMachineFaultIsReport")
    @ResponseBody
    public JsonMsgDto getMachineFaultIsReport(Integer signalMachineId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signalMachineFaultService.getMachineFaultIsReport(signalMachineId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/reportMachineFault")
    @ResponseBody
    public JsonMsgDto reportMachineFault(Integer signalMachineId, Integer machineCreatorId, Integer machineLevel, Integer machineType,
                                         String machinePhoto, String machineReason, Double machineMoney, Integer machineOrgId, Integer machineMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            signalMachineFaultService.reportMachineFault(signalMachineId, machineCreatorId, machineLevel, machineType,
                    machinePhoto, machineReason, machineMoney, machineOrgId, machineMainOrgId);
            //为空是app端作判断
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getMachineFaultList4App")
    @ResponseBody
    public JsonMsgDto getMachineFaultList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size)
            throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineFaultService.getMachineFaultList4App(orgId,actorIds,faultStatus,count,size));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteMachineFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteMachineFaultByIds(String machineFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineFaultService.deleteMachineFaultByIds(machineFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getMachineCoordinate4Map")
    @ResponseBody
    public JsonMsgDto getMachineCoordinate4Map(Integer orgId, Integer actorId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineFaultService.getMachineCoordinate4Map(orgId, actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getMachineEnergyByXY")
    @ResponseBody
    public JsonMsgDto getMachineEnergyByXY(String longitude, String latitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineFaultService.getMachineEnergyByXY(longitude, latitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getMachineFaultReport4DT")
    @ResponseBody
    public DTResponseDto getMachineFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId, String signalMachineStartRoad, String signalMachineEndRoad) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signalMachineFaultService.getMachineFaultReport4DT(dtRequestDto, actorId, orgId, signalMachineStartRoad, signalMachineEndRoad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signalMachineFaultService.getStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signalMachineFaultService.getSectionByStartRoad(roadName,actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }
}
